package unipi.helpers;

import java.util.List;
import java.util.Map;

import unipi.database.Notifications;
import unipi.database.Rights;
import unipi.database.User;

public class Sidebar
{
	private static String getProfileBar(String userID)
	{
		Map<String, String> userData = User.getUserData(userID);
		
		if(userData == null) return "Database Error. User not found."; //should never happen
		
		String name = userData.get("name") + " " + userData.get("surname");
		
		return  "<a  class=\"side_title\" href=\"Profile\">" + name + "</a>" +
				"<ul class=\"sideList\">" +
				"<li><a class=\"sideLink\"  href=\"Profile\">Προφίλ</a></li>" +
				"<li><a class=\"sideLink\" href=\"Logout\">Αποσύνδεση</a></li>" +
				"</ul>";		
		
	}
	
	private static String getNotificationBar(String userID)
	{
		List<String> notifications = Notifications.getNotifications(userID);
		String html = "";
		
		if(notifications == null) return null;
		
		html += "<div class=\"side_title\">Ειδοποιήσεις</div>";
		html += "<ul class=\"sideList\">";
		for(String not : notifications)
		{
			html += "<li>" + not + "</li>";			
		}
		html += "</ul>";
		
		return html;		
	}
	
	private static String getAdminToolsBar(String userID)
	{
		Map<String, Boolean> rights = Rights.getRights(userID);
		
		if(rights == null) return null;
		
		String content = "<div  class=\"side_title\">Εργαλεία Διαχείρησης</div>" +
						 "<ul class=\"sideList\">";
		
		boolean flag = false;
		
		if(rights.get("taskRights")) 
		{
			content += "<li><a  class=\"sideLink\" href=\"NewTask\">Ανάθεση Εργασιών</a></li>";
			content += "<li><a  class=\"sideLink\" href=\"ViewTasks?view=mytasks\">Εμφάνιση Εργασιών</a></li>";
			flag = true;
		}
		if(rights.get("userRights"))
		{
			content += "<li><a  class=\"sideLink\" href=\"ManageRequests\">Αιτήσεις Χρηστών</a></li>";
			content += "<li><a  class=\"sideLink\" href=\"GiveRights\">Ανάθεση Δικαιωμάτων</a></li>";
			content += "<li><a  class=\"sideLink\" href=\"EditRights\">Επεξεργασία Δικαιωμάτων</a></li>";
			flag = true;
		}
		if(rights.get("dptRights"))
		{
			content += "<li><a  class=\"sideLink\" href=\"NewDepartment\">Δημιουργία Τμημάτων</a></li>";
			content += "<li><a  class=\"sideLink\" href=\"EditDepartment\">Επεξεργασία Τμημάτων</a></li>";
			flag = true;
		}
		
		if(!flag) return null;
		
		content += "</ul>";
		
		return content;		
	}
	
	public static String[] getSidebarHTML(String userID)
	{
		return new String[]{getProfileBar(userID), getNotificationBar(userID), getAdminToolsBar(userID)}; 	
	}
	
	
	
}
